package org.imaginedays.androidall.utils;

import org.imaginedays.androidall.app.AndroidAllApp;
import org.imaginedays.androidall.constants.Constants;

import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

/**
 * 获取设备信息 工具类
 * 
 * @author imaginedays
 * 
 */
public class DeviceInfoUtils {

	private Context context;
	private WindowManager wm;
	private DisplayMetrics dm;

	public DeviceInfoUtils(Context context) {
		super();
		this.context = context;
		wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		dm = new DisplayMetrics();
		wm.getDefaultDisplay().getMetrics(dm);
	}

	/**
	 * 
	 */
	public DisplayMetrics getDisplayMetrics() {
		return dm;
	}

	/**
	 * 设置设备屏幕信息
	 */
	public void setDeviceScreenInfo() {
		int width = dm.widthPixels;
		int height = dm.heightPixels;
		int dpi = dm.densityDpi;
		float density = dm.density;
		Log.i(AndroidAllApp.TAG, "width: " + width + " height: " + height
				+ " dpi: " + dpi + " density: " + density);
	}

	/**
	 * android 获取设备Id等信息 <uses-permission
	 * android:name="android.permission.READ_PHONE_STATE"/>
	 */
	public void getDeviceInfo() {
		TelephonyManager tm = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		StringBuilder sb = new StringBuilder();
		sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());
		sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());
		sb.append("\nLine1Number = " + tm.getLine1Number());
		sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());
		sb.append("\nNetworkOperator = " + tm.getNetworkOperator());
		sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());
		sb.append("\nNetworkType = " + tm.getNetworkType());
		sb.append("\nPhoneType = " + tm.getPhoneType());
		sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
		sb.append("\nSimOperator = " + tm.getSimOperator());
		sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
		sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
		sb.append("\nSimState = " + tm.getSimState());
		sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
		sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());
		Log.e("info", sb.toString());
	}

	public void getDeviceBuildInfo() {
		Build build = new Build();
		Constants.BOARD = build.BOARD;
		Constants.BOOTLOADER = build.BOOTLOADER;
		Constants.BRAND = build.BRAND;
		Constants.CPU_ABI = build.CPU_ABI;
		Constants.CPU_ABI2 = build.CPU_ABI2;
		Constants.DEVICE = build.DEVICE;
		Constants.DISPLAY = build.DISPLAY;
		Constants.FINGERPRINT = build.FINGERPRINT;
		Constants.HARDWARE = build.HARDWARE;
		Constants.HOST = build.HOST;
		Constants.ID = build.ID;
		Constants.MANUFACTURER = build.MANUFACTURER;
		Constants.MODEL = build.MODEL;
		Constants.PRODUCT = build.PRODUCT;
		Constants.SERIAL = build.SERIAL;
		Constants.TAGS = build.TAGS;
		Constants.TIME = build.TIME;
		Constants.TYPE = build.TYPE;
		Constants.UNKNOWN = build.UNKNOWN;
		Constants.USER = build.USER;
		
		
	}
}
